package com.educate.pojo.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import static com.educate.pojo.response.ResultCode.ERROR;
import static com.educate.pojo.response.ResultCode.SUCCESS;


/**
 * 统一返回结果Bean
 * @author xiongyu
 * @date 2021/10/29 21:22
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ResultBean {

    /**
     * 状态值：本次请求response状态结果
     */
    private Integer status;
    /**
     * 描述：对本次状态码的描述
     */
    private String desc;
    /**
     * 数据：本次返回的数据
     */
    private Object data;


    public static ResultBean success(){
        return new ResultBean(SUCCESS.getCode(),SUCCESS.getMsg(),null);
    }

    public static ResultBean success(Object data){
        return new ResultBean(SUCCESS.getCode(),SUCCESS.getMsg(),data);
    }


    public static ResultBean fail(Integer status, String desc){
        return new ResultBean(status,desc,null);
    }

    public static ResultBean fail(ResultCode resultCode){
        return new ResultBean(ERROR.getCode(), ERROR.getMsg(),null);
    }


}
